package ru.gerunn.silent.common;

import java.util.concurrent.Callable;

import ru.gerunn.silent.exception.SilentReadMessageException;
import ru.gerunn.silent.exception.SilentWriteMessageException;
import ru.gerunn.silent.message.Message;

public class RWCallable implements Callable<Object> {

	private RWO rwo;

	public RWCallable(Reader reader, Writer writer) {
		rwo = new RWO(reader, writer);
	}

	public Object call() throws SilentReadMessageException, SilentWriteMessageException {
		Message message;
		while ((message = rwo.getReader().read()) != null) {
			rwo.getWriter().write(message);
		}
		return null;
	}

}
